package com.qzsoft.zhjd.laboratory.modules.marshallStabilityNew.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.common.utils.ZhjdIotUtils;
import com.qzsoft.zhjd.laboratory.modules.marshallStabilityNew.entity.MarshallStabilityNewResEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.qzsoft.zhjd.laboratory.modules.marshallStabilityNew.entity.MarshallStabilityNewEntity;
import com.qzsoft.zhjd.laboratory.modules.marshallStabilityNew.service.MarshallStabilityNewService;

import javax.servlet.http.HttpServletRequest;

/**
 * 马歇尔稳定度测定仪
 *
 * @author sx
 * @email 
 * @date 2023-07-11 18:56:39
 */
@RestController
@RequestMapping("laboratory/marshallStabilityNew")
public class MarshallStabilityNewController {

    @Autowired
    private MarshallStabilityNewService marshallStabilityNewService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("laboratory:marshallStabilityNew:page")
    public Result page(@RequestParam Map<String, Object> params){
        IPage page = marshallStabilityNewService.queryPage(params);
        return ResultUtils.ok(page);
    }

    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    @RequiresPermissions("laboratory:marshallStabilityNew:find")
    public Result find(@PathVariable("id") String id){
		MarshallStabilityNewEntity marshallStabilityNew = marshallStabilityNewService.getInfo(id);
        return ResultUtils.ok(marshallStabilityNew);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("laboratory:marshallStabilityNew:save")
    public Result save(@RequestBody MarshallStabilityNewEntity marshallStabilityNew){
		marshallStabilityNewService.saveData(marshallStabilityNew);
        return ResultUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("laboratory:marshallStabilityNew:update")
    public Result update(@RequestBody MarshallStabilityNewEntity marshallStabilityNew){
        marshallStabilityNewService.updateData(marshallStabilityNew);
        return ResultUtils.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("laboratory:marshallStabilityNew:delete")
    public Result deleteOne(@PathVariable("id") String id){
        marshallStabilityNewService.deleteOneData(id);
        return ResultUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("laboratory:marshallStabilityNew:delete")
    public Result delete(@RequestBody String[] ids){
        marshallStabilityNewService.deleteData(Arrays.asList(ids));
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public Result parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        System.out.println((new Date()) + "传入数据");
        marshallStabilityNewService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

    /**
     * 重新解析历史数据马歇尔航天科宇v2.X版本；
     * @param deviceId
     * @return
     */
    @PostMapping("/reParsingData/{deviceId}")
    public Result reParsingData(@PathVariable("deviceId") String deviceId){
        marshallStabilityNewService.reParsingData(deviceId);
        return ResultUtils.ok();
    }

    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    @RequiresPermissions("laboratory:marshallStabilityNew:changeSample")
    public Result changeSample(@RequestBody MarshallStabilityNewResEntity marshallStabilityNewRes){
        marshallStabilityNewService.changeSample(marshallStabilityNewRes);
        return ResultUtils.ok();
    }

    /**
     * 沥青混合料马歇尔稳定度试验仪 -- 北京中科建仪电子科技有限公司
     */
    @PostMapping("/parsingDataMarshallBjzkjydz/{deviceId}")
    public Result parsingDataMarshallBjzkjydz(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        marshallStabilityNewService.parsingDataMarshallBjzkjydz(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }


    /**
     * 云检科技 - 马歇尔稳定度试验仪
     */
    @PostMapping("/parsingDataMarshallYjkj/{deviceId}")
    public Result parsingDataMarshallYjkj(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        marshallStabilityNewService.parsingDataMarshallYjkj(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

}
